﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlDoc = HtmlAgilityPack.HtmlDocument;
using WebFunctions;
using Newtonsoft.Json;
using System.IO;
using System.Windows.Forms;

namespace AutoIndustryFiles
{
    class rockwellScraper:FileLinksScraper2
    {
        public rockwellScraper()
        {
            this.MainPage = "http://www.rockwellautomation.com/zh_CN/support/library.page?";
            this.CompanyName = "罗克韦尔自动化";
            this.CompanyUrl = "http://www.rockwellautomation.com/zh_CN/support/library.page?";
            this.ColumnName = "主页 -> 支持 -> 支持资源 -> 中文资料下载中心";
            //this.ReviseXPath += new OnReviseXPath(FuJiScraper_ReviseXPath);            
        }

        public override void GenerateAllLinks(string param)
        {
            string url = @"http://www.rockwellautomation.com/zh_CN/support/library.page?";

            string[] ps = File.ReadAllLines(Application.StartupPath + "\\Config\\rockwell.subcategory.point.txt");

            string content = WebFuncs.OpenUrlEx(url, "UTF-8");

            HtmlDoc doc = new HtmlDoc();
            doc.LoadHtml(content);

            string s = "";

            //生成第二级类别
            /*foreach (HtmlAgilityPack.HtmlNode node in doc.DocumentNode.SelectNodes(@"//table[@class=""tb""]//th[@class=""ltpurplebkg""]"))
            {
                s = s + System.Web.HttpUtility.HtmlDecode(node.InnerText.Trim()) + Environment.NewLine;
            }
            File.WriteAllText(@"D:\外包项目\自动化资料下载\Output\rockwell\细类.txt", s);*/
            foreach (HtmlAgilityPack.HtmlNode node in doc.DocumentNode.SelectNodes(@"//table[@class=""tb"" and position() < 11]//tr[td]"))
            {
                FileLink lnk = new FileLink();
                lnk.Id = FileLinks.Count.ToString();
                lnk.Name = System.Web.HttpUtility.HtmlDecode(node.SelectSingleNode("td[1]").InnerText.Trim());
                lnk.Url = FormatUrl(node.SelectSingleNode("td[2]/a").GetAttributeValue("href", ""),"http://www.rockwellautomation.com/");
                lnk.CategoryPath = "";
                lnk.IsFileLink = true;
                lnk.FileType = "";
                lnk.ReleaseDate = node.SelectSingleNode("td[3]").InnerText.Trim();
                FileLinks.Add(lnk);
            }
        }
    }
}
